package com.xmy.cultivate.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xmy.cultivate.entity.SkillStationsItems;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 培训岗位、项目 Mapper 接口
 * </p>
 *
 * @author hpiggy
 * @since 2025-08-21
 */
public interface SkillStationsItemsMapper extends BaseMapper<SkillStationsItems> {

    @Select({
            "<script>",
            "SELECT" ,
                    "t1.* ," ,
                    "getSubjectsName(t1.subjects_id) AS subjects_name," ,
                    "t2.name as items_name," ,
                    "t3.`name` AS station_name" ,
                    "FROM" ,
                    "skill_stations_items AS t1" ,
                    "LEFT JOIN skill_items_set AS t2 ON t1.items_id = t2.id" ,
                    "LEFT JOIN skill_stations AS t3 ON t3.id = t1.stations_id",
            "WHERE 1=1" ,
                    "AND t1.deleted = 0" ,
                    "<if test='itemId !=null and itemId != &apos;&apos;'>" ,
                    "AND t1.items_id = ${itemId}" ,
                    "</if>" ,

                    "<if test='type !=null and type != &apos;&apos;'>" ,
                    "AND t1.type = ${type}" ,
                    "</if>" ,

                    "<if test='subjectsId !=null and subjectsId != &apos;&apos;'>" ,
                    "AND t1.subjects_id = ${subjectsId}" ,
                    "</if>" ,

                    "<if test='stationsId !=null and stationsId != &apos;&apos;'>" ,
                    "AND t1.stations_id = ${stationsId}" ,
                    "</if>" ,
                    "ORDER BY t1.created_at" ,

            "</script>"
    })
    public IPage<SkillStationsItems> findAll(
            IPage<?> iPage,
            @Param("itemId") String itemId,
            @Param("type") String type,
            @Param("stationsId") String stationsId,
            @Param("itemsId") String itemsId,
            @Param("subjectsId") String subjectsId);

}
